﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;

public class ChatHub : Hub
{
    static string GameStart = "gamestartmessage";
    static string GameEnd = "gameendmessage";
    static string GameUpdate = "gameupdate";
    static string AnnounceWinner = "winnerannounce";


    public void SendMessage(int userID, int weekID, string message)
    {
        Message m = new Message() { Date = DateTime.Now, UserID = userID, Note = message, WeekID = weekID };
        DataBase.Messages.InsertMessage(m);


        var user = DataBase.Users.GetUserWithID(userID.ToString());
        Clients.All.broadcastMessage(user.NickName, ((DateTime)m.Date).ToString("g"), m.Note, weekID); 
    }

    public void InsertComputerMessage(string message, int weekID, string style)
    {
        Message m = new Message() { Date = DateTime.Now, Note = message, WeekID = weekID, Computer = true, Style = style };
        DataBase.Messages.InsertMessage(m);


       // Clients.All.broadcastComputerMessage(m.Note, weekID, m.Style); 
    }

    public void InsertGameStart(string message, int weekID)
    {
        InsertComputerMessage(message, weekID, GameStart);
    }

    public void InsertGameEnd(string message, int weekID)
    {
        InsertComputerMessage(message, weekID, GameEnd);
    }

    public void InsertGameUpdate(string message, int weekID)
    {
        InsertComputerMessage(message, weekID, GameUpdate);
    }

    public void InsertAnnounceWinner(string message, int weekID)
    {
        InsertComputerMessage(message, weekID, AnnounceWinner);
    }
}
